<!DOCTYPE html>
<html>

<head lang="en">
	<meta charset="UTF-8">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1">

	<title>Arqma with PLE or XCY or TRTL Mining Pool - Admin Panel</title>

	<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script>
	<script src="//cdnjs.cloudflare.com/ajax/libs/jquery-timeago/1.6.3/jquery.timeago.min.js"></script>
	<script src="https://cdnjs.cloudflare.com/ajax/libs/mustache.js/3.0.1/mustache.min.js"></script>
	<link href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css" rel="stylesheet">
	<script src="//netdna.bootstrapcdn.com/bootstrap/3.1.1/js/bootstrap.min.js"></script>
	<link href="//netdna.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet">
</head>

<body>

	<div id="wrapper">

		<!-- Navigation -->
		<div class="nav-side-menu">
			<div class="brand"><a href="/">Admin Panel</a></div>
			<i class="fa fa-bars fa-2x toggle-btn" data-toggle="collapse" data-target="#menu-content"></i>
			<div class="menu-list">
				<ul id="menu-content" class="menu-content collapsed out">

					<li><a class="hot_link" data-page="admin/statistics.html" href="#">
							<i class="fa fa-bar-chart-o"></i> Statistics
						</a></li>

					<li><a class="hot_link" data-page="admin/monitoring.html" href="#monitoring">
							<i class="fa fa-eye"></i> Monitoring
						</a></li>

					<li><a class="hot_link" data-page="admin/userslist.html" href="#users_list">
							<i class="fa fa-users"></i> Users List
						</a></li>

					<li><a class="hot_link" data-page="admin/ports.html" href="#ports">
							<i class="fa fa-link"></i> Ports Usage
						</a></li>

					<li><a class="hot_link" data-page="admin/tools.html" href="#tools">
							<i class="fa fa-gears"></i> Tools
						</a></li>

					<li class="sign-out"><a class="hot_link" href="/">
							<i class="fa fa-sign-out"></i> Return to Pool
						</a></li>

				</ul>
			</div>
		</div>

		<!-- Page content -->
		<div id="page-wrapper">
			<div id="page"></div>
			<p id="loading" class="text-center"><i class="fa fa-circle-o-notch fa-spin"></i></p>
		</div>

	</div>

	<!-- Footer -->
	<footer>
		<div class="text-muted">
			Powered by <a target="_blank" href="https://github.com/dvandal/cryptonote-nodejs-pool"><i class="fa fa-github"></i> cryptonote-nodejs-pool</a>
			<span id="poolVersion"></span>
			<span class="hidden-xs">open sourced under the <a href="http://www.gnu.org/licenses/gpl-2.0.html">GPL</a></span>
		</div>
	</footer>

	<!-- Javascript -->
	<script src="config.js"></script>
	<script src="js/common.js"></script>
	<script>
		// Fetch pool statistics
		lastStats = {};
		mergedStats = {};
		let mergedApis = {};

		$(function () {


			let merged_apis = $.ajax({
				url: `${api}/get_apis`,
				dataType: 'json',
				cache: 'false'
			})

			let poolStats = $.ajax({
				url: `${api}/stats`,
				dataType: 'json',
				cache: 'false'
			})

			Promise.all([poolStats, merged_apis])
				.then(values => {
					lastStats = values[0]
					mergedApis = values[1]
					let subs = [];
					Object.keys(mergedApis)
						.some(key => {
							let apiUrl = `${mergedApis[key].api}/stats`
							subs.push($.ajax({
								url: apiUrl,
								dataType: 'json',
								cache: 'false'
							}))
						})
					Promise.all(subs)
						.then(data => {
							data.forEach(item => {
								mergedStats[item.config.coin] = item
							})
							$('#poolVersion')
								.html(lastStats.config.version);
							routePage();
						})
				})
		});

		function fetchLiveStats () {
			$.ajax({
					url: api + '/live_stats',
					dataType: 'json',
					cache: 'false'
				})
				.done(function (data) {
					if (currentPage.update) {
						currentPage.update();
					}
				})
				.always(function () {
					fetchLiveStats();
				});
		}


		function renderTemplate (usersData, templateId, view) {
			let source = $(templateId)
				.html()
			Mustache.parse(source)
			let rendered = Mustache.render(source, usersData)
			$(view)
				.append(rendered)
		}

		// Initialize
		$(function () {
			$("head")
				.append("<link rel='stylesheet' href=" + themeCss + ">");
			$("head")
				.append("<link rel='stylesheet' href=themes/admin.css>");
			$("head")
				.append("<link rel='stylesheet' href=themes/custom.css>");
		});

	</script>

</body>

</html>
